-
Notifications
You must be signed in to change notification settings - Fork 22
INFRA-388 Converting smartmon into python and adding mock tests #1327
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: stackhpc/2024.1
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great start, many thanks. It would be good to investigate external libraries for the smart data collection / parsing.
93fd068
to
146b26c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @technowhizz , good effort.
|
||
def create_mock_device_from_json(self, device_info, if_attributes=None): | ||
""" | ||
Given a 'device_info' dict and optional 'if_attributes', build |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you create an actual pySmart device object here from the file output?
Eg. https://github.com/truenas/py-SMART/blob/master/tests/test_device.py#L43
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I gave this a shot but it turns out that it also requires a mock for smartctl and this made it a lot more complicated to just use a pySmart device. I think it makes more sense to mock it here
…re for better error reporting
c0da0ea
to
e0bae71
Compare
for metric in sorted(metrics): | ||
metric_name = metric.split("{")[0] | ||
if metric_name != last_metric: | ||
output.append(f"# HELP smartmon_{metric_name} SMART metric {metric_name}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please can you switch to the Prometheus library here? It is a slight change that it will write directly to a file for scraping. The advantage is that it handles all the metric formatting. A rough example:
from prometheus_client import CollectorRegistry, Gauge, write_to_textfile
metric_registry = CollectorRegistry()
metric_output_path = os.environ['SMART_METRIC_OUTPUT_PATH'])
for metric in metrics:
g = Gauge(metric_name, 'some help stirng', registry=registry)
g.set(metric_value)
write_to_textfile(metric_output_path, registry)
https://prometheus.github.io/client_python/exporting/textfile/
No description provided.